{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 1 Stream Deck(s).\n",
      "\n",
      "Deck 0 - Stream Deck (Original).\n",
      "\t - ID: b'0001:0009:00'\n",
      "\t - Serial: 'AL07I1C0830'\n",
      "\t - Firmware Version: '1.0.170133\u0000\u0000'\n",
      "\t - Key Count: 15 (3x5 grid)\n",
      "\t - Key Images: 72x72 pixels, BMP format, rotated 0 degrees, mirrored horizontally/vertically\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/env python3\n",
    "\n",
    "#         Python Stream Deck Library\n",
    "#      Released under the MIT license\n",
    "#\n",
    "#   dean [at] fourwalledcubicle [dot] com\n",
    "#         www.fourwalledcubicle.com\n",
    "#\n",
    "\n",
    "# Example script that prints out information about any discovered StreamDeck\n",
    "# devices to the console.\n",
    "\n",
    "from StreamDeck.DeviceManager import DeviceManager\n",
    "\n",
    "\n",
    "# Prints diagnostic information about a given StreamDeck\n",
    "def print_deck_info(index, deck):\n",
    "    image_format = deck.key_image_format()\n",
    "\n",
    "    flip_description = {\n",
    "        (False, False): \"not mirrored\",\n",
    "        (True, False): \"mirrored horizontally\",\n",
    "        (False, True): \"mirrored vertically\",\n",
    "        (True, True): \"mirrored horizontally/vertically\",\n",
    "    }\n",
    "\n",
    "    print(\"Deck {} - {}.\".format(index, deck.deck_type()), flush=True)\n",
    "    print(\"\\t - ID: {}\".format(deck.id()), flush=True)\n",
    "    print(\"\\t - Serial: '{}'\".format(deck.get_serial_number()), flush=True)\n",
    "    print(\"\\t - Firmware Version: '{}'\".format(deck.get_firmware_version()), flush=True)\n",
    "    print(\"\\t - Key Count: {} ({}x{} grid)\".format(\n",
    "        deck.key_count(),\n",
    "        deck.key_layout()[0],\n",
    "        deck.key_layout()[1]), flush=True)\n",
    "    print(\"\\t - Key Images: {}x{} pixels, {} format, rotated {} degrees, {}\".format(\n",
    "        image_format['size'][0],\n",
    "        image_format['size'][1],\n",
    "        image_format['format'],\n",
    "        image_format['rotation'],\n",
    "        flip_description[image_format['flip']]), flush=True)\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    streamdecks = DeviceManager().enumerate()\n",
    "\n",
    "    print(\"Found {} Stream Deck(s).\\n\".format(len(streamdecks)))\n",
    "\n",
    "    for index, deck in enumerate(streamdecks):\n",
    "        deck.open()\n",
    "        deck.reset()\n",
    "\n",
    "        print_deck_info(index, deck)\n",
    "\n",
    "        deck.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "deck = streamdecks[0]\n",
    "\n",
    "deck.close()\n",
    "deck.open()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(<StreamDeck.Devices.StreamDeckOriginal.StreamDeckOriginal object at 0x7f1148faf470>, 5, True)\n",
      "{}\n",
      "(<StreamDeck.Devices.StreamDeckOriginal.StreamDeckOriginal object at 0x7f1148faf470>, 5, False)\n",
      "{}\n",
      "(<StreamDeck.Devices.StreamDeckOriginal.StreamDeckOriginal object at 0x7f1148faf470>, 6, True)\n",
      "{}\n",
      "(<StreamDeck.Devices.StreamDeckOriginal.StreamDeckOriginal object at 0x7f1148faf470>, 6, False)\n",
      "{}\n",
      "(<StreamDeck.Devices.StreamDeckOriginal.StreamDeckOriginal object at 0x7f1148faf470>, 10, True)\n",
      "{}\n",
      "(<StreamDeck.Devices.StreamDeckOriginal.StreamDeckOriginal object at 0x7f1148faf470>, 10, False)\n",
      "{}\n"
     ]
    }
   ],
   "source": [
    "dir(deck)\n",
    "\n",
    "def my_key_callback(*args, **kwargs):\n",
    "    print(args)\n",
    "    print(kwargs)\n",
    "\n",
    "\n",
    "deck.set_key_callback(my_key_callback)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from subprocess import run\n",
    "\n",
    "\n",
    "def my_callback(*args, **kwargs):\n",
    "    print(\"hi\")\n",
    "\n",
    "from StreamDeck.DeviceManager import DeviceManager\n",
    "streamdecks = DeviceManager().enumerate()\n",
    "deck = streamdecks[0]\n",
    "if not deck.connected():\n",
    "    deck.connect()\n",
    "deck.set_key_callback(my_callback)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
